#include "opencv2/text.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/text/ocr.hpp"
#include <iostream>
/*#include <allheaders.h> // leptonica main header for image io
#include <baseapi.h> // tesseract main header*/
using namespace std;
using namespace cv;
using namespace cv::text;

void textRecognition(Mat & img, string &text)
{
	//adaptiveThreshold(img, img, 255, 0, THRESH_BINARY_INV, 3, 0);
	//threshold(img, img, 120, 255, THRESH_BINARY_INV);
	//copyMakeBorder(img, img, 15, 15, 15, 15, BORDER_CONSTANT, Scalar(0));
	//pyrUp(img, img);
	//threshold(img, img, 100, 255, CV_THRESH_OTSU | THRESH_BINARY_INV);
	GaussianBlur(img, img, Size(3,3),1);
	imshow("ostu", img);
	waitKey(0);
	Ptr<OCRTesseract> ocr = OCRTesseract::create();
	ocr->setWhiteList("0123456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ");
	/*vector<Rect>   boxes;
	vector<string> words;
	vector<float>  confidences;
	ocr->run(img, text, &boxes, &words, &confidences, 1);*/
	text = ocr->run(img, 15, 0);
	
}
/*void textRecognition(Mat & img, string &text)
{
	//adaptiveThreshold(img, img, 255, 0, THRESH_BINARY_INV, 3, 0);
	tesseract::TessBaseAPI tess;
	tesserInit(tess);
	threshold(img, img, 120, 255, THRESH_BINARY_INV);
	tess.SetImage((uchar*)img.data, img.size().width, img.size().height, img.channels(), img.step1());
	tess.Recognize(0);
	const char* text1 = tess.GetUTF8Text();
	//Ptr<OCRTesseract> ocr = OCRTesseract::create();
	//text = ocr->run(img, 0.2, OCR_LEVEL_TEXTLINE);
}*/
